﻿using System;
using System.Web;
using System.IO;
using System.Xml;
using System.Text;
using System.Web.SessionState;

namespace SISMHost
{
    public class WcfReadEntityBodyMode : IHttpModule
    {

        private static string _soap;

        public string SOAP { 
            get { return _soap; }
            set { _soap = value; }  
        }


        public void Dispose()
        {
            string p = "";
        }

        public void Init(HttpApplication context)
        {
            context.BeginRequest += context_BeginRequest;
        }

        void context_BeginRequest(object sender, EventArgs e)
        {
            #region Estraggo la busta SOAP dall'HTTP Handler

            var request = ((HttpApplication)sender).Request;

            var bytes = new byte[request.InputStream.Length];
            request.InputStream.Read(bytes, 0, bytes.Length);
            request.InputStream.Position = 0;
            SOAP = Encoding.ASCII.GetString(bytes);

#if DEBUG
    if (SOAP.StartsWith("???"))
        SOAP = SOAP.Substring(3, SOAP.Length - 3);
#endif
            
            #endregion
        }
    } 
}
